package com.example.nbshangpping.goods;


import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.nbshangpping.R;
import com.example.nbshangpping.utils.URLUtils;
import com.squareup.picasso.Picasso;

import java.util.List;
public class LikeAdapter extends BaseAdapter {
    Context context;
    List<GoodsBean.DataBean>data;
    public LikeAdapter(Context context, List<GoodsBean.DataBean>data){
        this.context=context;
        this.data=data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int pos) {
        return data.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {
        VH vh=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_like,parent,false);
            vh=new VH(convertView);
            convertView.setTag(vh);
        }
        else{
            vh=(VH) convertView.getTag();
        }
        GoodsBean.DataBean dataBean=data.get(pos);
        vh.titleTv.setText(dataBean.getName());
        String photo =dataBean.getPhoto();
        if (!TextUtils.isEmpty(photo)){
            String photourl= URLUtils.PUBLIC_URL+photo;
            Picasso.with(context).load(photourl).into(vh.iv);
        }
        return convertView;
    }
    class VH{
        TextView titleTv;
        ImageView iv;
        public  VH(View v){
            titleTv=v.findViewById(R.id.item_like_tv);
            iv=v.findViewById(R.id.item_like_iv);
        }

    }
}